package com.fulu.game.bi.service.impl.play;

import com.fulu.game.bi.common.util.csv.CsvExportUtil;
import com.fulu.game.bi.common.util.csv.Mapper;
import com.fulu.game.bi.common.util.csv.Querier;
import com.fulu.game.bi.common.util.lang.StringUtils;
import com.fulu.game.bi.entity.bo.channel.GameNewPlayeeRemainListBO;
import com.fulu.game.bi.entity.enums.DataTypeEnum;
import com.fulu.game.bi.entity.enums.QueryTypeStatusEnum;
import com.fulu.game.bi.entity.vo.play.GameNewPlayeeRemainStatVO;
import com.fulu.game.bi.hbase.HBaseGameNewPlayeeRemainStatDAO;
import com.fulu.game.bi.redis.service.play.GameNewPlayeeRemainService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class GameNewPlayeeRemainServiceImpl extends BasePlayService implements GameNewPlayeeRemainService {
    @Autowired
    private HBaseGameNewPlayeeRemainStatDAO hBaseGameNewPlayeeRemainStatDAO;

    @Override
    public List<GameNewPlayeeRemainStatVO> list(GameNewPlayeeRemainListBO listBO) {
        listBO.setTableName(gameNewPlayeeRemainListStat.get(listBO.getQueryType()));
        listBO.setDataType(StringUtils.isBlank(listBO.getCategoryName()) ? DataTypeEnum.ALL.getType() : DataTypeEnum.EACH.getType());
        List<GameNewPlayeeRemainStatVO> list = hBaseGameNewPlayeeRemainStatDAO.list(listBO);
        return list.stream().map(map -> {
            map.setCategoryName(StringUtils.isBlank(listBO.getCategoryName()) ? "/" : listBO.getCategoryName());
            map.setQueryType(listBO.getQueryType());
            return map;
        }).collect(Collectors.toList());
    }

    @Override
    public void export(GameNewPlayeeRemainListBO bo) {
        String fileName = "新陪玩师留存";
        LinkedHashMap<String, Mapper<GameNewPlayeeRemainStatVO>> map = new LinkedHashMap<>();
        QueryTypeStatusEnum anEnum = QueryTypeStatusEnum.getEnum(bo.getQueryType());
        String site = anEnum.getMsg();
        switch (anEnum) {
            case DAY:
                map.put("日期", v -> v.getStartDate());
                map.put("品类", v -> v.getCategoryName());
                map.put("新增陪玩师人数", v -> v.getNewAddPlayeeNum() + "");
                map.put("第1" + site + "活跃人数", v -> v.getLivelyPlayeeNum1() + "");
                map.put("第2" + site + "活跃人数", v -> v.getLivelyPlayeeNum2() + "");
                map.put("第3" + site + "活跃人数", v -> v.getLivelyPlayeeNum3() + "");
                map.put("第4" + site + "活跃人数", v -> v.getLivelyPlayeeNum4() + "");
                map.put("第5" + site + "活跃人数", v -> v.getLivelyPlayeeNum5() + "");
                map.put("第6" + site + "活跃人数", v -> v.getLivelyPlayeeNum6() + "");
                map.put("第7" + site + "活跃人数", v -> v.getLivelyPlayeeNum7() + "");
                map.put("第14" + site + "活跃人数", v -> v.getLivelyPlayeeNum14() + "");
                map.put("第30" + site + "活跃人数", v -> v.getLivelyPlayeeNum30() + "");
                map.put("第1" + site + "接单人数", v -> v.getOrderPlayeeNum1() + "");
                map.put("第2" + site + "接单人数", v -> v.getOrderPlayeeNum2() + "");
                map.put("第3" + site + "接单人数", v -> v.getOrderPlayeeNum3() + "");
                map.put("第4" + site + "接单人数", v -> v.getOrderPlayeeNum4() + "");
                map.put("第5" + site + "接单人数", v -> v.getOrderPlayeeNum5() + "");
                map.put("第6" + site + "接单人数", v -> v.getOrderPlayeeNum6() + "");
                map.put("第7" + site + "接单人数", v -> v.getOrderPlayeeNum7() + "");
                map.put("第14" + site + "接单人数", v -> v.getOrderPlayeeNum14() + "");
                map.put("第30" + site + "接单人数", v -> v.getOrderPlayeeNum30() + "");
                break;
            default:
                map.put("日期", v -> v.getStartDate() + "-" + v.getEndDate());
                map.put("品类", v -> v.getCategoryName());
                map.put("新增陪玩师人数", v -> v.getNewAddPlayeeNum() + "");
                map.put("1" + site + "活跃人数", v -> v.getLivelyPlayeeNum1() + "");
                map.put("2" + site + "活跃人数", v -> v.getLivelyPlayeeNum2() + "");
                map.put("3" + site + "活跃人数", v -> v.getLivelyPlayeeNum3() + "");
                map.put("4" + site + "活跃人数", v -> v.getLivelyPlayeeNum4() + "");
                map.put("5" + site + "活跃人数", v -> v.getLivelyPlayeeNum5() + "");
                map.put("6" + site + "活跃人数", v -> v.getLivelyPlayeeNum6() + "");
                map.put("7" + site + "活跃人数", v -> v.getLivelyPlayeeNum7() + "");
                map.put("8" + site + "活跃人数", v -> v.getLivelyPlayeeNum8() + "");
                map.put("9" + site + "活跃人数", v -> v.getLivelyPlayeeNum9() + "");
                map.put("10" + site + "活跃人数", v -> v.getLivelyPlayeeNum10() + "");
                map.put("11" + site + "活跃人数", v -> v.getLivelyPlayeeNum11() + "");
                map.put("12" + site + "活跃人数", v -> v.getLivelyPlayeeNum12() + "");
                map.put("1" + site + "接单人数", v -> v.getOrderPlayeeNum1() + "");
                map.put("2" + site + "接单人数", v -> v.getOrderPlayeeNum2() + "");
                map.put("3" + site + "接单人数", v -> v.getOrderPlayeeNum3() + "");
                map.put("4" + site + "接单人数", v -> v.getOrderPlayeeNum4() + "");
                map.put("5" + site + "接单人数", v -> v.getOrderPlayeeNum5() + "");
                map.put("6" + site + "接单人数", v -> v.getOrderPlayeeNum6() + "");
                map.put("7" + site + "接单人数", v -> v.getOrderPlayeeNum7() + "");
                map.put("8" + site + "接单人数", v -> v.getOrderPlayeeNum8() + "");
                map.put("9" + site + "接单人数", v -> v.getOrderPlayeeNum9() + "");
                map.put("10" + site + "接单人数", v -> v.getOrderPlayeeNum10() + "");
                map.put("11" + site + "接单人数", v -> v.getOrderPlayeeNum11() + "");
                map.put("12" + site + "接单人数", v -> v.getOrderPlayeeNum12() + "");
                break;
        }
        Querier querier = (num) -> {
            PageInfo pageInfo = new PageInfo(list(bo));
            pageInfo.setHasNextPage(false);
            return pageInfo;
        };
        CsvExportUtil.export(100, fileName, map, querier);


    }

    @Override
    public List<String> newPlayee() {
        return hBaseGameNewPlayeeRemainStatDAO.newPlayee();
    }
}
